package nodes.command;

import java.util.List;
import java.util.Random;
import parser.ParserException;
import model.Model;
import nodes.AbstractNode;
import nodes.ConstantNode;


/**
 * Returns a random non-negative integer less than its argument
 */
public class RandomC extends AbstractCommand
{
    public AbstractNode evaluate (List<AbstractNode> myArguments, Model model)
    {
        if (myArguments.size() != Integer.parseInt(resources.getString("random")))
        {
            throw ParserException.BAD_ARGUMENTS;
        }

        Random generator = new Random();

        return new ConstantNode(generator.nextInt((int) myArguments.get(0).evaluate().getValue()));
    }
}
